package bch.maven.plugin.controller;

import bch.maven.plugin.event.SyncResultEvent;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

/**
 * @author DCJ
 */
@RestController
@RequiredArgsConstructor
@RequestMapping
@Slf4j
public class BestPractice {
    private final ApplicationEventPublisher applicationEventPublisher;

    @GetMapping("/hello")
    public String hello() {
        SyncResultEvent event = new SyncResultEvent(this, null);
        applicationEventPublisher.publishEvent(event);
        Object result = event.getResult();
        log.info("{} result: {}", Thread.currentThread().getName(), result.toString());
        return "hello world";
    }
}
